/**
 * 
 */
package com.witframework.web.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;

/**
 * @author wuxinyang
 * Jul 10, 2009 2:15:12 PM
 * 
 */
public class Rquestfilter  implements Filter {
	static final String CP="/WEB-INF/classes/";
	public void doFilter(ServletRequest req, ServletResponse res,FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = (HttpServletRequest) req;
		HttpServletResponse response = (HttpServletResponse) res;
		int classes;
		String uri=request.getRequestURI();
		if((classes=uri.indexOf(CP))>0){
			uri=uri.substring(classes+CP.length());
			String queryString=request.getQueryString();
			request.getRequestDispatcher(uri+(StringUtils.isNotEmpty(queryString)?"?"+queryString:"")).forward(request,response);
		}else{
			chain.doFilter(request, response);
		}
	}
	public void init(FilterConfig filterConfig) throws ServletException {			
	}	
	public void destroy() {		
	}	
}
